"use strict";

var Q = require('q'),
    nodemailer = require("nodemailer");

function MailerService() {
    console.log("MailerService constructor");
    this.smtpTransport = nodemailer.createTransport("SMTP",{
        service: "AOL",
        auth: {
            user: "protolocal@aol.fr",
            pass: "JmBc2014"
        }
    });
}

MailerService.prototype.send = function (subject, to, text, html) {
    var self = this;

    var mailOptions = {
        from: "Proto Local<protolocal@aol.fr>",
        to: to,
        subject: subject,
        text: text,
        html: html
    };

    return Q.ninvoke(self.smtpTransport, 'sendMail', mailOptions).fail(function (error) {
        console.log("Failed to send. ", error);
    });
};

exports = module.exports = new MailerService();